using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentData;
using AdverseEventReportSystem.Model;
using AdverseEventReportSystem.Core;

namespace AdverseEventReportSystem.Repository 
{
    public	class AdverseEventYcFanKuiRepository:BaseRepository<AdverseEventYcFanKui> {

        #region 构造函数
     
	    private static AdverseEventYcFanKuiRepository _instance;
	    public static AdverseEventYcFanKuiRepository GetInstance() {
            if (_instance == null) {
                _instance = new AdverseEventYcFanKuiRepository();
            }
            return _instance;
        }
     
        #endregion

	    #region Add
     
	    public int  Add(AdverseEventYcFanKui entity, IDbContext context = null) {
            if (context == null) context = Db.GetInstance().Context();
		    int Id = context.Insert<AdverseEventYcFanKui>("AdverseEventYcFanKui", entity)
			        .AutoMap(x => x.ID)
                    .ExecuteReturnLastId<int>();
		    return Id;
	    }
     
	    #endregion

	    #region Update
        
	    public int Update(AdverseEventYcFanKui entity, IDbContext context = null) {
            if (context == null) context = Db.GetInstance().Context();
		    int rowsAffected = context.Update<AdverseEventYcFanKui>("AdverseEventYcFanKui", entity)
                    .AutoMap(x => x.ID)
        		    .Where(x => x.ID)
        		    .Execute();
		    return rowsAffected;
	    }
        
	    #endregion

        #region 获取单个实体 通过主键ID
        
	    /// <summary>
	    /// 获取单个实体 通过主键ID
	    /// </summary>
	    /// <param name="id">主键ID</param>
		/// <param name="context">数据库连接对象</param>
		/// <returns></returns>
		public virtual AdverseEventYcFanKui GetQuerySingleByID(int id, IDbContext context = null) {
				if (context == null) context = Db.GetInstance().Context();
            Object[] objects = new Object[1];
			objects[0] = id;
			string sqlStr = "SELECT * FROM AdverseEventYcFanKui WHERE ID=@0";
			AdverseEventYcFanKui obj = GetQuerySingle(sqlStr, context, objects);
			return obj;
		}
        
		#endregion
        
        #region 删除操作  通过ID
        
        /// <summary>
		/// 删除操作  通过ID
		/// </summary>
		/// <param name="id">主键ID</param>
		/// <param name="context">数据库连接对象</param>
		/// <returns></returns>
		public virtual int DelByID(int id, IDbContext context = null) {
          	if (context == null) context = Db.GetInstance().Context();
            Object[] objects = new Object[1];
			objects[0] = id;
			string sqlStr = "DELETE FROM AdverseEventYcFanKui WHERE ID=@0";
			return Del(sqlStr, context, objects);
		}

	    #endregion

        #region 根据不良事件ID获取实体

        /// <summary>
        /// 根据不良事件ID获取实体
        /// </summary>
        /// <param name="eventId">不良事件ID</param>
        /// <param name="context">数据库连接对象</param>
        /// <returns></returns>
        public virtual AdverseEventYcFanKui GetQuerySingleByEventID(int eventId, IDbContext context = null)
        {
            if (context == null) context = Db.GetInstance().Context();
            Object[] objects = new Object[1];
            objects[0] = eventId;
            string sqlStr = "SELECT * FROM AdverseEventYcFanKui WHERE EventID=@0";
            AdverseEventYcFanKui obj = GetQuerySingle(sqlStr, context, objects);
            return obj;
        }

        #endregion

        #region 根据不良事件ID删除实体

        /// <summary>
        /// 根据不良事件ID删除实体
        /// </summary>
        /// <param name="id">不良事件ID</param>
        /// <param name="context">数据库连接对象</param>
        /// <returns></returns>
        public virtual int DelByEventID(int eventId, IDbContext context = null)
        {
            if (context == null) context = Db.GetInstance().Context();
            Object[] objects = new Object[1];
            objects[0] = eventId;
            string sqlStr = "DELETE FROM AdverseEventYcFanKui WHERE EventID=@0";
            return Del(sqlStr, context, objects);
        }

        #endregion
    }
}





